﻿import "babel-polyfill"
import Vue from 'vue'
import Router from 'vue-router'
import routes from "./router.js"
import App from './app'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import store from './store'
import { getUserInfo } from '@/utils/auth'

import * as filters from '@/filters/'

import ServerMixin from './mixin/ServerMixin'

import '../theme/iconfont/iconfont.css'
import '../theme/common.scss'

Vue.use(ElementUI);
Vue.use(ServerMixin);
Vue.use(Router);

Object.keys(filters).forEach(key => {
    Vue.filter(key, filters[key]);
})

const router = new Router({ routes });


// 拦截白名单
// const whiteList = ['/login'];

// router.beforeEach((to, from, next) => {

//     if (getUserInfo()) {

//         if (to.path == '/login') {
//             next({
//                 path: "/"
//             });
//         } else {
//             next();
//         }
//         /*if (to.path === '/login') {
//             next({
//                 path: '/'
//             });
//         } else {
//             next();
//         }*/
//     } else {
//         if (whiteList.indexOf(to.path) != -1) {

//             next();
//         } else {
//             next({
//                 path: '/login'
//             });
//         }

//     }
// });  
new Vue({
    el: '#app',
    template: '<App/>',
    router,
    store,
    components: { App },
    mounted() {
        // ServerMixin.Event.$on('login', (msg) => {
        //     this.$$alert({
        //             message: msg || '登录超时，请重新登录！',
        //             type: 'warning',
        //             showClose: false
        //         })
        //         .then(() => {
        //             this.$store.dispatch('logout')
        //                 .then(() => {
        //                     this.$router.push({
        //                         path: '/login',
        //                         query: {
        //                             redirectUrl: location.href
        //                         }
        //                     });
        //                 });
        //         });
        // })
    }
});